package com.congee02.modelshellmvn.controller;

import com.congee02.modelshellmvn.entity.plate.vo.PlateRecognitionResult;
import com.congee02.modelshellmvn.service.PlateRecognitionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

@RestController
public class PlateRecognitionController {

    @Resource
    private PlateRecognitionService plateRecognitionService;

    @GetMapping("recognize")
    public List<PlateRecognitionResult> recognizePlate(@RequestParam String imageUrl) throws MalformedURLException {
        return plateRecognitionService.recognizeByURL(
                new URL(imageUrl)
        );
    }

    @PostMapping("recognize")
    public List<PlateRecognitionResult> recognizePlate(@RequestPart("file") org.springframework.core.io.Resource resource) {
        return plateRecognitionService.recognizeByResource(
                resource
        );
    }

}
